/*
 * Filename H5ReportMapping.java 2022年05月18日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author wuyingchao
 */
package com.ehome.poct.core.service.mapping;

import cn.hutool.core.convert.Convert;
import cn.hutool.json.JSONUtil;
import com.ehome.poct.core.api.constant.enums.DiseaseRiskLevel;
import com.ehome.poct.core.api.dto.check.CheckItemIndicatorDTO;
import com.ehome.poct.core.api.dto.check.CheckProjectDTO;
import com.ehome.poct.core.api.dto.check.gold.TestConfPoctStripTypeDTO;
import com.ehome.poct.core.api.dto.check.gold.TestReportDiseaseConfigDTO;
import com.ehome.poct.core.api.dto.checkdata.BldCheckDataDTO;
import com.ehome.poct.core.api.dto.order.TestOrderDTO;
import com.ehome.poct.core.api.dto.patient.TermPatientDTO;
import com.ehome.poct.core.api.dto.report.BldAnalysisDTO;
import com.ehome.poct.core.api.dto.report.BldUniAnalysisDTO;
import com.ehome.poct.core.api.dto.report.ConfConclusionDTO;
import com.ehome.poct.core.api.vo.CheckChartDataVO;
import com.ehome.poct.core.api.vo.CheckResultVO;
import com.ehome.poct.core.api.vo.ResultImgVO;
import com.ehome.poct.core.api.vo.patient.PatientDetailVO;
import com.ehome.poct.core.api.vo.report.*;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author wyc
 * @since 2022/05/18 09:31
 **/
@Mapper(componentModel = "spring", imports = {JSONUtil.class, CheckChartDataVO.class, ResultImgVO.class, BigDecimal.class, Convert.class})
public interface H5ReportMapping {
    H5ReportDetailVO to(PatientDetailVO patient, ReportBaseContentVO base, ReportDataVO reportData,
                        BldReportAnalysisVO analysis, BldReportAnalysisVO rbcAnalysis, List<DiseaseCategoryVO> diseaseCategory, String pushLink);

    @Mapping(target = "reqId", source = "data.algoReqId")
    @Mapping(target = "checkTime", source = "data.createTime")
    @Mapping(target = "reportName", source = "project.checkProjectName")
    @Mapping(target = "orderNo", source = "order.testOrderNo")
    ReportBaseContentVO to(BldCheckDataDTO data, CheckProjectDTO project, TestOrderDTO order);

    @Mapping(target = "conclusion.name", source = "name")
    @Mapping(target = "conclusion.img", source = "img")
    @Mapping(target = "conclusion.color", source = "color")
    BldReportAnalysisVO to(BldAnalysisDTO dto);

    @Mapping(target = "conclusion.name", source = "name")
    @Mapping(target = "conclusion.img", source = "img")
    @Mapping(target = "conclusion.color", source = "color")
    BldReportAnalysisVO to(BldUniAnalysisDTO dto);

    ReportConclusionVO to(ConfConclusionDTO dto);

    @Mapping(target = "conclusion", source = "conclusion")
    BldReportAnalysisVO to(@MappingTarget BldReportAnalysisVO analysis,  ConfConclusionDTO conclusion);

    @Mapping(target = "patientId", source = "termPatientId")
    @Mapping(target = "clinicId", source = "termClinicId")
    @Mapping(target = "userName", source = "name")
    @Mapping(target = "mobilePhone", source = "phone")
    @Mapping(target = "userAge", source = "age")
    @Mapping(target = "userMonth", source = "month")
    @Mapping(target = "userSex", source = "sex")
    PatientDetailVO to(TermPatientDTO entity);

    @Mapping(target = "rrs", source = "kpi.reference")
    @Mapping(target = "type", source = "kpi.simpleName")
    @Mapping(target = "order", source = "kpi.projectItemId")
    CheckResultVO to(@MappingTarget CheckResultVO result, CheckItemIndicatorDTO kpi);

    @Mapping(target = "typeName", source = "strip.fullName")
    @Mapping(target = "type", expression = "java(strip.getName().replaceAll(\"检测\", \"\"))")
    @Mapping(target = "rrs", source = "strip.reference")
    @Mapping(target = "order", source = "strip.typeCode")
    @Mapping(target = "code", constant = "3")
    @Mapping(target = "status", ignore = true)
    CheckResultVO to(TestConfPoctStripTypeDTO strip);

    @Mapping(target = "displayColor", source = "risk.color")
    @Mapping(target = "levelName", source = "risk.desc")
    @Mapping(target = "level", source = "risk.level")
    DiseaseDtlVO to(TestReportDiseaseConfigDTO dto, DiseaseRiskLevel risk);

//    default String compareColor(BigDecimal valueA, BigDecimal valueB, TestReportDiseaseConfigDTO entity) {
//        var diseaseJudgeFactory = SpringUtil.getBean(DiseaseJudgeFactory.class);
//        var diseaseJudge = diseaseJudgeFactory.createJudge(entity.getJudgeMode());
//        // 找不到对应的判断模式，返回正常颜色
//        if (diseaseJudge == null) {
//            return "#4ca9ff";
//        }
//        return diseaseJudge.judgeColor(valueA, valueB, entity);
//    }

}